#include <iostream>
#include <string>

using namespace std;

struct TREE
{
    char data;
    TREE* left;
    TREE* right;
};

TREE* creat_TREE(string p,string m)
{
    if(p.size()==0)
    {
        cout<<"error input"<<endl;
        return NULL;
    }
    
        TREE* t=(TREE*) new TREE;
        t->data=p[0];

        int index=m.find(p[0]);
        cout<<"the indexis"<<index<<endl;
        string pl,pr,ml,mr;
        pl=p.substr(1,index);
        pr=p.substr(index+1,p.size()-1-index);
        ml=m.substr(0,index);
        mr=m.substr(index+1,p.size()-1-index);
        t->left=creat_TREE(pl,ml);
        t->right=creat_TREE(pr,mr);

        return t;
   
}

void rear_tree(TREE* &t)
{
    if(t)
    {
        rear_tree(t->left);
        rear_tree(t->right);
        cout<<t->data;
    }
}

int main()
{
    string p1,m1;

    while(cin>>p1>>m1)
    {
        TREE* t=creat_TREE(p1,m1);
        rear_tree(t);
        cout<<endl;
    }

    system("pause");
    return 0;
}

